"""
类
"""

from db import db_handler


# 公共基类
class Base:
    @classmethod
    def select(cls, name):
        obj = db_handler.select_data(cls, name)
        return obj

    def save(self):
        db_handler.save_data(self)


# 管理员类
class Admin(Base):
    def __init__(self, username, password):
        self.name = username
        self.pwd = password
    
    def register(self):
        self.save()

    def login(self, password):
        if self.pwd == password:
            return True
        else:
            return False
    
    def create_school(self, school_name):
        school_obj = School(school_name)
        school_obj.save()

    def create_course(self, school_obj, course_name):
        course_obj = Course(course_name)
        course_obj.save()

        school_obj.course_list.append(course_name)
        school_obj.save()

    def add_teacher(self, teacher_name, password):
        teacher_obj = Teacher(teacher_name, password)
        teacher_obj.save()


# 学生类
class Student(Base):
    def __init__(self, username, password):
        self.name = username
        self.pwd = password
        self.school = None
        self.course_list = []
        self.score_dict = {}
    
    def register(self):
        self.save()

    def login(self, password):
        if self.pwd == password:
            return True
        else:
            return False
    
    def select_school(self, school_name):
        self.school = school_name
        self.save()
    
    def select_course(self, course_name):
        self.course_list.append(course_name)
        self.score_dict[course_name] = 0
        self.save()

        course_obj = Course.select(course_name)
        course_obj.student_list.append(self.name)
        course_obj.save()

    def check_score(self):
        return self.score_dict


# 老师类
class Teacher(Base):
    def __init__(self, teacher_name, password):
        self.name = teacher_name
        self.pwd = password
        self.course_list = []
    
    def login(self, password):
        if self.pwd == password:
            return True
        else:
            return False
    
    def check_teach_course(self):
        return self.course_list
    
    def select_teach_course(self, course_name):
        self.course_list.append(course_name)
        self.save()

    def check_stu_of_course(self, course_name):
        course_obj = Course.select(course_name)
        return course_obj.student_list
    
    def modify_stu_score(self, course_name, student, score):
        student_obj = Student.select(student)
        student_obj.score_dict[course_name] = score
        student_obj.save()



# 学校类
class School(Base):
    def __init__(self, school_name):
        self.name = school_name
        self.course_list = []


# 课程类
class Course(Base):
    def __init__(self, course_name):
        self.name = course_name
        self.student_list = []

